package com.git_taoxian.test4;

import java.io.*;
import java.net.Socket;

public class ClientTest {
    public static void main(String[] args) {
        try {
//        获取客户端对象
            Socket socket = new Socket("127.0.0.1", 8009);
//        获取字节输入输出流
            InputStream is = socket.getInputStream();
            OutputStream os = socket.getOutputStream();
//        包装低级流为高级流
            File file = new File("d:/haha/my.txt");
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
            byte[] buf = new byte[1024];
            int len;
            while((len= is.read(buf))!=-1){
                bos.write(buf,0,len);
            }
            System.out.println("下载已完成");
//        释放资源
            bos.close();
            is.close();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
